﻿using System;
using System.Linq;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using ASPNETVN.PORTAL.Components.Helpers;
using ASPNETVN.PORTAL.Components.UI;
using ASPNETVN.PORTAL.Modules.MENU.Components;
using System.Collections.Generic;
using ASPNETVN.PORTAL.Components.Configuration.Settings;
using ASPNETVN.PORTAL.Components.UI.DataTypes;

namespace ASPNETVN.PORTAL.Modules.MENU
{
    public enum ModulePages
    {
        StaticMenu,
        SlideOutMenu,
        OneLevel1,
        SlideDownMenu,
        OneLevel1CDTM,
        BulletListArcodionMenu,
        MooToolMenu
    }

    public partial class Main : PortalModuleControl
    {
        public Main()
        {
            // Define an Array List
            ArrayList list = new ArrayList();
            list.Add(new ListItem("StaticMenu", "StaticMenu"));
            list.Add(new ListItem("SlideOutMenu", "SlideOutMenu"));
            list.Add(new ListItem("OneLevel1", "OneLevel1"));
            list.Add(new ListItem("SlideDownMenu", "SlideDownMenu"));
            list.Add(new ListItem("OneLevel1CDTM", "OneLevel1CDTM"));
            list.Add(new ListItem("BulletListArcodionMenu", "BulletListArcodionMenu"));
            list.Add(new ListItem("MooToolMenu", "MooToolMenu"));

            ModuleSettingItem itemSetting = new ModuleSettingItem(new CustomListDataType(list, "Text", "Value"));
            itemSetting.Value = "OneLevel1CDTM";
            itemSetting.Name = "Hình thức hiển thị";
            itemSetting.Description = "Hình thức hiển thị";
            itemSetting.SortOrder = 1;
            this.BaseSettings.Add("DisplayStyle", itemSetting);

            itemSetting = new ModuleSettingItem(new StringDataType("SlideDownMenu.css"));
            itemSetting.Name = "Css File";
            itemSetting.Description = "Css File";
            itemSetting.SortOrder = 1;
            this.BaseSettings.Add("CssFile", itemSetting);
        }

        private void LoadChildControl()
        {
            const string basePath = "~/Modules/ASPNETVN.PORTAL.Modules.MENU/";
            ModulePages page = (ModulePages)Enum.Parse(typeof(ModulePages), this.Settings["DisplayStyle"].ToString(), true);
            string src = string.Format("{0}Controls/{1}.ascx", basePath, page);
            ModulePage ctl = (ModulePage)this.LoadControl(src);
            ctl.ParentControl = this;
            Container.Controls.Add(ctl);
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            this.ModuleTitle.AddUrl = HttpUrlBuilder.BuildAddEditUrl(this.ModuleID, 0, "ItemManager");
            this.LoadChildControl();
        }
    }
}